package com.boot.core.entity;/**
 * @description
 * @autor xbwu on 2018/5/14.
 */

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * mybatis-plus基类实体
 * @author xbwu
 * @create 2018-05-14 
 **/
@Data
public class BaseMpEntity<T extends Model> extends Model<T> {
    /**
     * 主键ID
     */
    @TableId("id")
    @Column(name = "id",type = MySqlTypeConstant.BIGINT,isNull = false,isKey = true)
    protected Long id;

    @TableField(value = "tenant_id")
    @Column(name = "tenant_id",type = MySqlTypeConstant.BIGINT,isNull = false)
    protected Long tenantId;

    /**
     *  1有效，0无效
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name = "valid",type = MySqlTypeConstant.INT,isNull = false)
    protected Boolean valid;
    /**
     * 修改时间
     * 因为调用更新和插入的方法时，会验证你所传的属性是否为空，来判断是否该更新和插入这个属性
     * 这个就和MP的公共字段自动填充相冲突了，所以需要配置：fill = FieldFill.INSERT 来标识此属性是需要全局注入的。
     * 不然在插入的时候就会填充失败。具体值在MyMetaObjectHandler填入
     */
    @TableField(value = "modify_dateTime",fill = FieldFill.INSERT_UPDATE)
    @Column(name = "modify_dateTime",type = MySqlTypeConstant.DATETIME)
    protected Date modifyDateTime;
    /**
     * 创建时间
     */
    @TableField(value = "create_dateTime",fill = FieldFill.INSERT)
    @Column(name = "create_dateTime",type = MySqlTypeConstant.DATETIME,isNull = false)
    protected Date createDateTime;
    /**
     * 操作人
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name = "operator",type = MySqlTypeConstant.VARCHAR,length = 50)
    protected String operator;


    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
